import { defineStore } from 'pinia';

export const useAuthStore = defineStore('auth', {
  state: () => ({
    token: null,
  }),
  actions: {
    setToken(token) {
      this.token = token;
      // 可以在这里将 token 存储到 localStorage 或 sessionStorage
      localStorage.setItem('token', token);
    },
    clearToken() {
      this.token = null;
      // 清除本地存储中的 token
      localStorage.removeItem('token');
    },
    getToken() {
      return this.token || localStorage.getItem('token');
    }
  },
});